package com.ra.quartz;

import com.ra.mapper.ElasticsearchMapper;
import com.ra.pojo.Article;
import com.ra.pojo.dto.ArticleSearchDTO;
import com.ra.service.IArticleService;
import com.ra.utils.BeanCopyUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Author : 今晚几点睡_Ada
 * Date: 2023/3/24
 * Time: 12:08
 * 注:
 */
@Slf4j
@Component("myQuartz")
public class MyQuartz {
    @Autowired
    private IArticleService articleService;
    @Autowired
    private ElasticsearchMapper elasticsearchMapper;

    //文章导入ES
    public void importDataIntoES() {
        elasticsearchMapper.deleteAll();
        List<Article> articles = articleService.list();
        for (Article article : articles) {
            elasticsearchMapper.save(BeanCopyUtil.copyObject(article, ArticleSearchDTO.class));
        }
    }
}
